package com.ruoyi.door.utils;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;

public class CgiBin {
    public static JSONObject getAccessToken(String appId, String appSecret) throws JSONException {
        try {
            //{"errcode":40164,"errmsg":"invalid ip 180.168.137.250 ipv6 ::ffff:180.168.137.250, not in whitelist rid: 67b3dcd0-37fe8529-2e6d0394"}
            String token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET";
            //wx414ff50b380ad2bc,d5abb348c475b1a6704477df4d90803f
            String requestUrl = token_url.replace("APPID", appId).replace("APPSECRET", appSecret);
            // 发起GET请求获取凭证
            return JSONObject.parseObject(HttpUtil.createGet(requestUrl).execute().body());

        } catch (JSONException e) {
            return null;
        }
    }
}
